<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller{
	/**
     * 构造函数
     *
     * @access  public
     * @return  void
     */
	public function __construct(){
		parent::__construct();
		$this->load->helper('download');
	}
	
	// ------------------------------------------------------------------------

    /**
     * 默认入口
     *
     * @access  public
     * @return  void
     */	
	function index(){
		$dateatter = array();
		$remember = $this->input->post('remember');
		if($this->user_auth->login(urldecode($this->input->post('username')), $this->input->post('password'), $remember)){
			//$this->db->where('id',$this->session->userdata('user_id'))->delete('sms_check');
			$this->db->update('sms_check', array('check_read'=>'1'),array('u_id'=>$this->session->userdata('user_id'))); 
			$dateatter['success'] = true;
			$dateatter['message'] = $this->user_auth->messages();
			$dateatter['useractual'] = $this->session->userdata('user_actual');
			$dateatter['userid'] = $this->session->userdata('user_id');
		}else{
			$dateatter['success'] = false;
			$dateatter['message'] = $this->user_auth->errors();	
		}
		echo json_encode($dateatter);
		
	}

	//log the user out
	function logout(){
		$this->user_auth->logout();
	}
	
	function get_settings_site(){
		$data = $this->user_m->settings_site();
		echo $data->site_name;
	}
	
	function version_oa(){
		$query = $this->db->select('client_verCode')->get('site_settings');
		$row = $query->row(); 
		$verName = (float) $row->client_verCode.'.0';
		$verObj = array(  
			'verName'=>$verName,
			'verCode'=>$row->client_verCode
			);
		echo("[".json_encode($verObj)."]");
	}

	function newver(){
		$data = file_get_contents(FCPATH."attach\mobile\Oa.apk"); // 读文件内容
		$name = 'Oa.apk';
		
		force_download($name, $data);
	}
	function android_ewm(){
		header('Location: '.base_url().'attach/mobile/Oa.apk');
		exit();
	}

}
